package com.tom.architect02.p4.day37.simple4;

import com.tom.architect02.p4.day35.simple2.BaseSubscriber;
import com.tom.architect02.p4.day37.simple4.base.BasePresenter;

/**
 * Added by Tom on 2024/01/26.
 * 基类+泛型。
 */
public class UserInfoPresenter
        extends BasePresenter<UserInfoContact.UserInfoView>
        implements UserInfoContact.UserInfoPresenter {
    private UserInfoContact.UserInfoModel mModel;

    // view传递进来
    public UserInfoPresenter() {
        this.mModel = new UserInfoModel();
    }


    @Override
    public void getUser(String token) {
        getView().onLoading();

        // 获取数据。
        mModel.getUsers(token).subscribe(new BaseSubscriber<UserInfo>() {
            @Override
            protected void onError(String errorCode, String errorMessage) {
                // 失败。
                if (getView() != null)
                    getView().onError();
            }

            @Override
            public void onNext(UserInfo userInfo) {
                // 成功
                if (getView() != null)
                    getView().onSucceed(userInfo);
            }
        });
    }

}
